﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DAWSharp.UI.WinFormsControls
{
    public partial class SongContainer : UserControl
    {
        public Int64 songLengthSamples { get; set; }
        private int _hZoomPercent;
        private float _hZoom
        {
            get
            {
                return _hZoomPercent / 100.0f;
            }
        }
        private Int64 _samplesPerPixel
        {
            get
            {
                return (Int64)((songLengthSamples * _hZoom));
            }
        }
        private Int64 _leftMostSample
        {
            get
            {
                return 1;
            }
        }
        private Int64 _rightMostSample
        {
            get
            {
                return (Int64)(_leftMostSample + (songLengthSamples * (1 / _hZoom)));
            }
        }


        public SongContainer()
        {
            InitializeComponent();

            _hZoomPercent = 10;
            songLengthSamples = 522080;

            hScrollBar.Maximum = (int)((_hZoom * 100) * songLengthSamples);
            hScrollBar.Minimum = 1;


            WPFWaveDisplayContainer nya = new WPFWaveDisplayContainer(@"C:\TEST\SHORTTESTMONO.WAV", _leftMostSample, _rightMostSample, _samplesPerPixel);
            this.panelSong.Controls.Add(nya);
        }

        public override string ToString()
        {
            return string.Format("songLengthSamples:{0} | _leftMostSample:{1} | _rightMostSample:{2} | _hZoomPercent:{3} | _hZoom:{4} | _samplesPerPixel:{5} | this.panelSong.Width:{6}"
                , songLengthSamples
                , _leftMostSample
                , _rightMostSample
                , _hZoomPercent
                , _hZoom
                , _samplesPerPixel
                , this.panelSong.Width);

        }

        public void Redraw()
        {
            Console.WriteLine(this.ToString());
            hScrollBar.Maximum = (int)((_hZoom * 100) * songLengthSamples);
            hScrollBar.Minimum = 1;
        }

        private void buttonDecHZoom_Click(object sender, EventArgs e)
        {
            if (_hZoomPercent > 1)
            {
                _hZoomPercent--;
                Redraw();
            }
        }

        private void buttonIncHZoom_Click(object sender, EventArgs e)
        {
            if (_hZoomPercent < 100)
            {
                _hZoomPercent++;
                Redraw();
            }
        }

        private void buttonAutoZoom_Click(object sender, EventArgs e)
        {

        }

        private void buttonDecVZoom_Click(object sender, EventArgs e)
        {

        }

        private void buttonIncVZoom_Click(object sender, EventArgs e)
        {

        }

        private void hScrollBar_Scroll(object sender, ScrollEventArgs e)
        {
            Redraw();
        }
    }
}
